<?php namespace Phpcmf\Controllers\Admin;

// 日志
class Home extends \Phpcmf\Table
{
    private $catid;

    public function __construct(...$params)
    {
        parent::__construct(...$params);
        // 判断云市场
        if (!dr_is_app('cloud')) {
            $this->_admin_msg(0, '你没有安装[私有云市场]插件，请在插件商城中安装它');
        }
        $cloud = \Phpcmf\Service::M('app')->get_config('cloud');
        if (!isset($cloud['cloud']['catid'][58]) || !$cloud['cloud']['catid'][58]) {
            $this->_admin_msg(0, '需要在[私有云市场]插件的-云端关联-关联小程序栏目');
        }
        $this->catid = intval($cloud['cloud']['catid'][58]);
        $module = $this->get_cache('module-'.SITE_ID.'-cloud');
        $category = $module['category'][$this->catid];
        if (!$category) {
            $this->_admin_msg(0, '[私有云市场]插件的小程序栏目['.$this->catid.']不存在');
        }
        // 表单显示名称
        $this->name = dr_lang('市场商品');
        // 模板前缀(避免混淆)
        $this->tpl_prefix = 'shop_';
        // 初始化数据表
        $this->_init([
            'table' => SITE_ID.'_cloud', // 表的名字
            'field' => $module['field'], // 设置入库字段
            'show_field' => 'title', // 表的主字段
            'where_list' => 'catid in ('.$category['childids'].')', // 表的主字段
            'order_by' => $this->module['setting']['order'],
            'list_field' => $this->module['setting']['list_field'],
        ]);
        \Phpcmf\Service::V()->assign([
            'field' => $module['field'],
            'menu' => \Phpcmf\Service::M('auth')->_admin_menu(
                [
                    $this->name => [APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/index', 'fa fa-shopping-cart'],
                    '添加商品' => ['cloud/home/add{catid='.$this->catid.'}', 'fa fa-plus'],
                ]
            ),
        ]);
    }

    public function index() {
        list($tpl) = $this->_List(); // 完成table自动查询并分页显示动作
        \Phpcmf\Service::V()->display($tpl); // 设定显示模板
    }


}
